#include <iostream>

using namespace std;

int max_array(int* number_array, unsigned int n);

int main() {
	unsigned int n;
	cin >> n;
	int* number_array = new int[n];
	for (unsigned int i = 0; i < n; i++) {
		cin >> *(number_array + i);
	}
	cout << max_array(number_array, n);
	delete[] number_array;
}

int max_array(int* number_array, unsigned int n) {
	int sum, maximum = -5000;
	for (unsigned int i = 0; i < n; i++) {
		sum = 0;
		for (unsigned int k = i; k < n; k++) {
			sum += *(number_array + k);
			if (sum > maximum) {
				maximum = sum;
			}
		}
	}
	return maximum;
}